package com.ean.backpack.core.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ean.backpack.domain.Role;
import com.ean.backpack.repository.RoleRepository;

/**
 * @author valentin
 *
 */
@Component
public class RoleUtils {

	@Autowired
	private RoleRepository roleRepository;

	public Role getRole(final String roleId) {
		Role result = roleRepository.findByRoleName(roleId);
		if (result == null) {
			result = new Role();
			result.setRoleName(roleId);
			roleRepository.save(result);
		}
		return result;
	}

}
